package com.xtm.exercise.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class CodeCreateUtil {
    private static ThreadLocal<DateFormat> threadLocal = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyyMMddHHmmss");
        }
    };
    public static   String  getCode(){
        String format = threadLocal.get().format(new Date());
        format="YYD"+format+getRandom2(4);
        return format;
    }

    public static   String  getReserveApplyCode(){
        String format = threadLocal.get().format(new Date());
        format="BM"+format+getRandom2(4);
        return format;
    }

    /**
     * 汇总单编号
     * @return
     */
    public static String getSummarySheetCode(){
        String format = threadLocal.get().format(new Date());
        format="HZ"+format+getRandom2(4);
        return format;
    }

    public static String getRandom2(int len) {
        Random r = new Random();
        StringBuilder rs = new StringBuilder();
        for (int i = 0; i < len; i++) {
            rs.append(r.nextInt(10));
        }
        return rs.toString();
    }
}
